package ONLINE_EXAM;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class aliOnline {
    /**
     * 滑窗想法
     * 相邻
     * 乘机结果大于target  那么就缩小
     * 小于就加入 然后再扩大
     *
     * 扩大时就判断收取结果
     * @param args
     */
    public static void main(String[] args) {
        aliOnline test = new aliOnline();
        int[] nums = new int[]{10,5,2,6};
        List<List<Integer>> res = test.slidingWindow(nums,100);

        for (List<Integer> out:res){
            //System.out.println(out.toArray());
            for (Integer i:out){
                System.out.print(nums[i]);
            }
            System.out.println();
        }

    }

    public List<List<Integer>> slidingWindow(int[] nums ,int target){
        List<List<Integer>> result = new ArrayList<>();
        ArrayList<Integer> window = new ArrayList<>();
        int left = 0;
        int right = 0;
        int res = 1;

        //window存索引
        while (right < nums.length){
            int in = nums[right];
            window.add(right);
            right++;
            res *= in;

            if (res <= target){
                result.add(new ArrayList<>(window));
            }else {
                while (res > target){
                    int out = nums[left];
                    window.remove(left);
                    left++;
                    res /= out;
                }
                result.add(window);
            }
        }
        return result;
    }
}
